<?php

namespace app\admin\service;

use app\admin\model\Menu as MenuModel;
use think\facade\Db;


class Menu
{
    public static function getAuthMenu()
    {
        $adminInfo = Administrator::info();

        $admin_role = $adminInfo['role_id'];
        $sql  = MenuModel::where('status', 0)->order('order asc');

        $tool = new Tool();
        if($admin_role == 1){
            $menus = $sql->select()->toArray();
        }else{
            $menuIds = Db::name('auth_role_menu')->where('role_id', $admin_role)->column('menu_id');
            $menus = $sql->whereIn('id',$menuIds)->select()->toArray();
        }

        $menus = assoc_unique($menus, 'id');

        return $tool->buildTree($menus, true);
    }
}